package com.petshop.service;

import com.common.constant.BalzLogger;
import com.petshop.dao.RegisterDao;
import com.petshop.dao.RegisterDaoImpl;
import com.petshop.model.User;


public class RegisterServiceImpl implements RegisterService {
	
	BalzLogger logger = new BalzLogger();

	@Override
	public Boolean checkUsernameExist(String username) {

		Boolean isExist = true;
		
		RegisterDao registerDao = new RegisterDaoImpl();
		isExist = registerDao.checkUsernameExist(username);
		
		return isExist;
	}

	@Override
	public Boolean checkEmailExist(String email) {
		
		Boolean isExist = true;
		
		RegisterDao registerDao = new RegisterDaoImpl();
		isExist = registerDao.checkEmailExist(email);
		
		return isExist;
	}

	@Override
	public void register(User user) {
		
		logger.debug("USER >> : "+user);
		
		RegisterDao registerDao = new RegisterDaoImpl();
		int userId = registerDao.registUserNamePassword(user);
		logger.debug("userId >> : "+userId);
		if(userId != 0){
			user.setUserId(Integer.toString(userId));
			registerDao.registProfile(user);
			registerDao.registRole(user);
		}
	}

	
}
